<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
       $model = $this->getModel();
       $aut = new bgAuthorize();
       
        switch(JRequest::getVar('task')){
            case 'error':
                $this->listcain=$model->getAllcain($this->list);
                $this->row = (object)JRequest::getVar('jform');              
                $this->row->INFO_BODY=$_POST['info_body'];  
                $this->row->INFO_TITLE=$_POST['info_subject'];
                // MAIL_USER
                //$this->rowuser = $model->loadlistuser($cid[0]);
                //$this->list['info_subject'] = &JRequest::getVar('info_subject');
                JToolBarHelper::title( 'インフォメーション編集', 'article.png' );

                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
       	        JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('a00710');
                break;
            case 'edit':
                $this->listcain=$model->getAllcain($this->list);
                $cid = JRequest::getVar('cid');
                $this->row = $model->load($cid[0]);                
                $this->rowuser = $model->loadlistuser($cid[0]);
                //print_r($this->row);return;
                //if($cid){
                  //  $this->row = $model->load($cid);
                //}else{
                  //  die('Not found');
                //}

                    JToolBarHelper::title( 'インフォメーション編集', 'article.png' );

                    JToolBarHelper::save2copy('savetemp','一時保存');
                    JToolBarHelper::save('save','登録');
           	        JToolBarHelper::cancel('cancel', 'キャンセル');
                    $this->setLayout('a00710');
      
              
                break;
            case 'popup_cadm':
                
                $this->list_cain =& $model->getAllCainPopup();
                               
                $this->setLayout('popup_cadm');
            break;
            case 'add':
            	JToolBarHelper::title( 'インフォメーション作成', 'article.png' );

                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
       	        JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('a00710');
                $this->listcain=$model->getAllcain($this->list);
                
                
               
            	break;   
             case 'popup':
                $usertype = $model->getAllUsertype();
                $mailgroup = $model->getAllMailGroup();
                $area = $model->getAllArea();
                $area_code = 0;
                $pref = $model->getAllPrefOfArea($area_code);
                
                $this->assignRef('usertype',$usertype);
                $this->assignRef('mailgroup',$mailgroup);
                $this->assignRef('area',$area);
                $this->assignRef('pref',$pref);
                
                $this->setLayout('popup');
                break;	  
                
            /*case 'popup_us':
        
                $this->setLayout('Popup_users');
                $this->rows =& $model->getAllUser($this->list);  
                $this->list['filter_search'] = &JRequest::getVar('filter_search');
                $this->pagination =& $this->get('PaginationUser');
        	break;
             case 'save':
                
             break;*/
            	    
            default :
                $this->list['filter_search'] = &JRequest::getVar('filter_search');
               
                $this->rows =& $model->getAll($this->list);  
                $this->pagination =& $this->get('Pagination');
                
            	JToolBarHelper::title( 'インフォメーション管理', 'article.png' );
                if($aut->checkAdd()){
                    JToolBarHelper::addNew('add','作成');
                }
               if($aut->checkEdit() || $aut->checkEditOwn()){
	              JToolBarHelper::editList('edit', '編集');
                 
              }
                if($aut->checkDelete()){
    	           JToolBarHelper::deleteList('', 'remove','削除');
                }
                $this->setLayout('a00700');
		}
        
		parent::display();
	}
}
